home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWSemEvt / Sources / FWPrtScp.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  9.8 KB  |  354 lines  |  [TEXT/MPS ]

  1.  
  2. //========================================================================================
  3. //
  4. //    File:                FWSemPrt.cpp
  5. //    Release Version:    $ ODF 1 $
  6. //
  7. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  8. //
  9. //========================================================================================
  10.  
  11. #ifndef FWPRTSCP_H
  12. #include "FWPrtScp.h"
  13. #endif
  14.  
  15. // ----- Framework Includes -----
  16.  
  17. #ifndef FWPART_H
  18. #include "FWPart.h"
  19. #endif
  20.  
  21. #ifndef FWDESC_H
  22. #include "FWDesc.h"
  23. #endif
  24.  
  25. #ifndef FWDSCOPR_H
  26. #include "FWDscOpr.h"
  27. #endif
  28.  
  29. #ifndef FWFRAME_H
  30. #include "FWFrame.h"
  31. #endif
  32.  
  33. #ifndef FWOBJSPC_H
  34. #include "FWObjSpc.h"
  35. #endif
  36.  
  37. #ifndef FWPRTITE_H
  38. #include "FWPrtIte.h"
  39. #endif
  40.  
  41. // ----- Foundation Includes -----
  42.  
  43. #ifndef FWPSTR_H
  44. #include "FWPStr.h"
  45. #endif
  46.  
  47. // ----- OpenDoc Includes -----
  48.  
  49. #ifndef SOM_Module_OpenDoc_ODRegistry_defined
  50. #include <ODRgstry.xh>
  51. #endif
  52.  
  53. #ifndef SOM_ODObjectSpec_xh
  54. #include <ODObjSpc.xh>
  55. #endif
  56.  
  57. // ----- Macintosh Includes -----
  58.  
  59. #ifndef __AEOBJECTS__
  60. #include <AEObjects.h>
  61. #endif
  62.  
  63. #ifndef __AEPACKOBJECT__
  64. #include <AEPackObject.h>
  65. #endif
  66.  
  67. //========================================================================================
  68. //    Runtime Information
  69. //========================================================================================
  70.  
  71. #ifdef FW_BUILD_MAC    
  72. #pragma segment fwsemevt
  73. #endif
  74.  
  75. FW_DEFINE_AUTO(FW_MPartScriptable)
  76. FW_DEFINE_AUTO(FW_MEmbeddingPartScriptable)
  77.  
  78. //========================================================================================
  79. //    class FW_MPartScriptable
  80. //========================================================================================
  81.  
  82. FW_DEFINE_CLASS_M1(FW_MPartScriptable, FW_MScriptable)
  83.  
  84. //---------------------------------------------------------------------------------------
  85. //    FW_MPartScriptable::FW_MPartScriptable
  86. //---------------------------------------------------------------------------------------
  87.  
  88. FW_MPartScriptable::FW_MPartScriptable() :
  89.     FW_MScriptable()
  90. {
  91.     FW_END_CONSTRUCTOR
  92. }
  93.  
  94. //---------------------------------------------------------------------------------------
  95. //    FW_MPartScriptable::~FW_MPartScriptable
  96. //---------------------------------------------------------------------------------------
  97.  
  98. FW_MPartScriptable::~FW_MPartScriptable()
  99. {
  100.     FW_START_DESTRUCTOR
  101. }                                                
  102.  
  103. //---------------------------------------------------------------------------------------
  104. //    FW_MPartScriptable::GetObjectClass
  105. //---------------------------------------------------------------------------------------
  106.  
  107. ODDescType FW_MPartScriptable::GetObjectClass() const
  108. {
  109.     return cPart;
  110. };
  111.  
  112. //---------------------------------------------------------------------------------------
  113. //    FW_MPartScriptable::GetSpecifierForm
  114. //---------------------------------------------------------------------------------------
  115.  
  116. ODDescType FW_MPartScriptable::GetSpecifierForm() const
  117. {
  118.     return formUniqueID;
  119. }
  120.  
  121. //---------------------------------------------------------------------------------------
  122. //    FW_MPartScriptable::EmbeddedFrameSpec
  123. //---------------------------------------------------------------------------------------
  124.  
  125. void FW_MPartScriptable::EmbeddedFrameSpec(Environment* ev,
  126.                                         FW_CPart* part,
  127.                                         FW_CFrame* embeddedFrame,
  128.                                         FW_CDesc& objectSpec)
  129. {
  130.     FW_CAcquiredODFrame aqContainingFrame = embeddedFrame->AcquireContainingFrame(ev);
  131.     if (aqContainingFrame != NULL)
  132.     {
  133.         FW_CDesc containerSpec;
  134.         
  135.         FW_CAcquiredODPart aqContainingPart = aqContainingFrame->AcquirePart(ev);
  136.         aqContainingPart->EmbeddedFrameSpec(ev, aqContainingFrame, containerSpec);
  137.     
  138.         FW_CPartFrameIterator iter(ev, part);
  139.         FW_CDesc mySpecData;
  140.     
  141.         FW_Boolean gotData = FALSE;
  142.     
  143.         long index = 1;
  144.         
  145.         for (FW_CFrame* frame = iter.First(ev); iter.IsNotComplete(ev) && !gotData; iter.Next(ev), index++)
  146.         {
  147.             if (frame == embeddedFrame)
  148.             {
  149.                 mySpecData << index;
  150.                 gotData = TRUE;
  151.             }
  152.         }
  153.         
  154.         if (gotData)
  155.             ::FW_CreateObjSpecifier(cPart, containerSpec, formAbsolutePosition, mySpecData, objectSpec);
  156.         else
  157.             FW_THROW(FW_XException(kODErrCannotEmbed));
  158.     }
  159.     else
  160.         objectSpec.Clear();
  161. }
  162.  
  163. //---------------------------------------------------------------------------------------
  164. //    FW_MPartScriptable::GetContainingObject
  165. //---------------------------------------------------------------------------------------
  166.  
  167. FW_MScriptable* FW_MPartScriptable::GetContainingObject(Environment* ev,
  168.                                                         FW_CPart* part) const
  169. {
  170. FW_UNUSED(ev);
  171. FW_UNUSED(part);
  172.     FW_THROW(FW_XException(errAEEventNotHandled));
  173.     return NULL;
  174. }
  175.  
  176. //---------------------------------------------------------------------------------------
  177. //    FW_MPartScriptable::GetObjectContainedInPart
  178. //---------------------------------------------------------------------------------------
  179.  
  180. FW_Boolean FW_MPartScriptable::GetObjectContainedInPart(Environment* ev,
  181.                                                     ODDescType desiredClass,
  182.                                                     ODDescType form,
  183.                                                     FW_CDesc& selectionData,
  184.                                                     FW_CDesc& containedObjectToken)
  185. {
  186. FW_UNUSED(ev);
  187. FW_UNUSED(desiredClass);
  188. FW_UNUSED(form);
  189. FW_UNUSED(selectionData);
  190. FW_UNUSED(containedObjectToken);
  191.     return FALSE;
  192. }
  193.  
  194. //---------------------------------------------------------------------------------------
  195. //    FW_MPartScriptable::CountElementsInPart
  196. //---------------------------------------------------------------------------------------
  197.  
  198. long FW_MPartScriptable::CountElementsInPart(Environment* ev,
  199.                                         ODDescType desiredClass)
  200. {
  201. FW_UNUSED(ev);
  202. FW_UNUSED(desiredClass);
  203.     FW_THROW(FW_XException(errAEEventNotHandled));
  204.     
  205.     return 0;
  206. }
  207.  
  208. //---------------------------------------------------------------------------------------
  209. //    FW_MPartScriptable::BuildObjectSpecifier
  210. //---------------------------------------------------------------------------------------
  211.  
  212. void FW_MPartScriptable::BuildObjectSpecifier(Environment* ev,
  213.                                             FW_CPart* part,
  214.                                             const FW_CFrame* frame,
  215.                                             FW_CDesc& specifier,
  216.                                             ODDescType preferredForm) const
  217. {
  218.     volatile FW_Boolean gotFrameSpec;
  219.     
  220.     FW_TRY
  221.     {
  222.         ODPart* odPart = part->GetODPart(ev);
  223.         odPart->EmbeddedFrameSpec(ev, frame->GetODFrame(ev), specifier);
  224.         
  225.         gotFrameSpec = TRUE;
  226.     }
  227.     FW_CATCH_BEGIN
  228.     FW_CATCH_EVERYTHING()
  229.     {
  230.         gotFrameSpec = FALSE;
  231.     }
  232.     FW_CATCH_END
  233.     
  234.     if (!gotFrameSpec)
  235.     {
  236.         if (preferredForm == formUniqueID)
  237.         {
  238.             FW_CDesc nullDesc;
  239.             FW_CDesc mySpecifier;
  240.             
  241.             ODPersistentObjectID id = part->GetDraft(ev)->GetPersistentObjectID(ev, frame->GetODFrame(ev), kODFrameObject);
  242.             mySpecifier.PutLongInteger(id);
  243.             
  244.             ::FW_CreateObjSpecifier(GetObjectClass(), nullDesc, preferredForm, mySpecifier, specifier);
  245.         }
  246.         else
  247.             FW_THROW(FW_XException(errAECantSupplyType));
  248.     }
  249. }
  250.  
  251. //---------------------------------------------------------------------------------------
  252. //    FW_MPartScriptable::HasProperty
  253. //---------------------------------------------------------------------------------------
  254.  
  255. FW_Boolean FW_MPartScriptable::HasProperty(ODDescType whichProperty) const
  256. {
  257.     return (whichProperty == pUniqueID);
  258. }
  259.  
  260. //---------------------------------------------------------------------------------------
  261. //    FW_MPartScriptable::GetProperty
  262. //---------------------------------------------------------------------------------------
  263.  
  264. FW_Boolean FW_MPartScriptable::GetProperty(Environment* ev,
  265.                                         FW_CPart* part,
  266.                                         FW_CDesc& propertyValue,
  267.                                         ODDescType whichProperty,
  268.                                         ODDescType desiredType) const
  269. {    
  270. FW_UNUSED(desiredType);
  271.     if (whichProperty == pUniqueID)
  272.     {    
  273.             // the part is being asked to provide a uniqueID, but there is no way
  274.             // to associate the id with any frame other than the last active frame.
  275.             // It is possible to get a persistent ID for the kODPartObject, but
  276.             // OpenDoc doesn't expect persistent part ID's when resolving object
  277.             // specifiers.
  278.             
  279.         ODFrame* frame = part->GetLastActiveFrame(ev)->GetODFrame(ev);
  280.         ODPersistentObjectID id = part->GetDraft(ev)->GetPersistentObjectID(ev,frame, kODFrameObject);
  281.         
  282.         propertyValue.PutLongInteger(id);
  283.         
  284.         return TRUE;
  285.     }
  286.     else
  287.         return FALSE;
  288. }
  289.  
  290. //---------------------------------------------------------------------------------------
  291. //    FW_MPartScriptable::EmbeddedFrameSpecGlue
  292. //---------------------------------------------------------------------------------------
  293.  
  294. void FW_MPartScriptable::EmbeddedFrameSpecGlue(Environment* ev,
  295.                                             FW_CPart* part,
  296.                                             ODFrame* embeddedFrame,
  297.                                             ODObjectSpec* spec)
  298. {
  299.     FW_TRY
  300.     {
  301.         FW_MPartScriptable* semanticPart = FW_DYNAMIC_CAST(FW_MPartScriptable, part);
  302.         
  303.         if (semanticPart)
  304.         {
  305.             FW_CDesc     objectSpec(spec);
  306.             FW_CFrame*     embeddedFWFrame = FW_CFrame::ODtoFWFrame(ev, embeddedFrame);
  307.             
  308.             semanticPart->EmbeddedFrameSpec(ev, part, embeddedFWFrame, objectSpec);
  309.         }
  310.         else
  311.             FW_SetEvError(ev, kODErrCannotEmbed);
  312.     }
  313.     FW_CATCH_BEGIN
  314.     FW_CATCH_REFERENCE(FW_XException, exception)
  315.     {
  316.         // kODErrCannotEmbed
  317.         FW_SetException(ev, exception);
  318.     }
  319. #ifdef FW_DEBUG
  320.     FW_CATCH_EVERYTHING()
  321.     {
  322.         // FW_DEBUG_MESSAGE(FW_kInvalidException);
  323.         FW_SetEvError(ev, kODErrUndefined);
  324.     }
  325. #endif
  326.     FW_CATCH_END
  327. }
  328. //========================================================================================
  329. //    class FW_MEmbeddingPartScriptable
  330. //========================================================================================
  331.  
  332. FW_DEFINE_CLASS_M1(FW_MEmbeddingPartScriptable, FW_MPartScriptable);
  333.  
  334. //---------------------------------------------------------------------------------------
  335. //    FW_MEmbeddingPartScriptable::FW_MEmbeddingPartScriptable
  336. //---------------------------------------------------------------------------------------
  337.  
  338. FW_MEmbeddingPartScriptable::FW_MEmbeddingPartScriptable() :
  339.     FW_MPartScriptable()
  340. {
  341.     FW_END_CONSTRUCTOR
  342. }
  343.  
  344. //---------------------------------------------------------------------------------------
  345. //    FW_MEmbeddingPartScriptable::~FW_MEmbeddingPartScriptable
  346. //---------------------------------------------------------------------------------------
  347.  
  348. FW_MEmbeddingPartScriptable::~FW_MEmbeddingPartScriptable()
  349. {
  350.     FW_START_DESTRUCTOR
  351. }
  352.  
  353.  
  354.